package com.sjp.service.impl;

import com.sjp.dao.BlogMapper;
import com.sjp.pojo.Blog;
import com.sjp.pojo.dto.BlogDto;
import com.sjp.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Override
    public List<BlogDto> queryAllBlog() {
        return blogMapper.queryAllBlog();
    }

    @Override
    public List<Blog> queryAllBlogForBlog() {
        return blogMapper.queryAllBlogForBlog();
    }

    @Override
    public List<BlogDto> pagingQuery(Integer start, Integer count) {
        return blogMapper.pagingQuery(start, count);
    }

    @Override
    public int deleteBlog(Integer[] ids) {
        return blogMapper.deleteBlog(ids);
    }

    @Override
    public List<BlogDto> queryBlogByTitleOrCategory(String keyword) {
        return blogMapper.queryBlogByTitleOrCategory(keyword);
    }

    // 查询已发布或未发布的博客总数
    @Override
    public int countBlog(Integer blogStatus) {
        if (blogStatus == 1) return blogMapper.countPublishedBlog();
        return blogMapper.countBlog();
    }

    @Override
    public int saveBlog(Blog blog) {
        return blogMapper.saveBlog(blog);
    }

    @Override
    public int updateBlog(Blog blog) {
        return blogMapper.updateBlog(blog);
    }

    @Override
    public Blog queryBlogById(Integer blogId) {
        return blogMapper.queryBlogById(blogId);
    }

    @Override
    public List<Blog> queryPublishedBlog() {
        return blogMapper.queryPublishedBlog();
    }

    @Override
    public List<BlogDto> queryTopViewsBlogs() {
        return blogMapper.queryTopViewsBlogs();
    }

    @Override
    public List<BlogDto> queryRentBlogs() {
        return blogMapper.queryRentBlogs();
    }

    @Override
    public List<BlogDto> queryForTagId(Integer tagId) {
        Integer[] ids = blogMapper.queryForTagId(tagId);
        if (ids.length != 0) return blogMapper.queryForBlogId(ids);
        else return null;
    }

    @Override
    public List<BlogDto> queryForCategoryId(Integer start, Integer count, Integer categoryId) {
        return blogMapper.queryForCategoryId(start, count, categoryId);
    }

    @Override
    public int countForCategoryId(Integer categoryId) {
        return blogMapper.countForCategoryId(categoryId);
    }

    @Override
    public boolean viewsIncr(Integer blogId) {
        return blogMapper.viewsIncr(blogId);
    }

    @Override
    public int updateBlogTag(Integer blogId, Integer[] tagIds) {
        return blogMapper.updateBlogTag(blogId, tagIds);
    }
}
